import java.sql.*;
public class LoginBean 
{
	Connection con;
	Statement st;
	ResultSet rs;
	String status="";
	public LoginBean()
	{
		try
		{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
			st=con.createStatement();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	public String checkLogin(String uname,String upwd)
	{
		try
		{
			rs=st.executeQuery("select * from registration where uname='"+uname+"'"+" and upwd='"+upwd+"'"+"");
			boolean b=rs.next();
			if(b==true)
			{
				status="success";
			}
			else
			{
				status="failure";
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return status;
	}
	public String registrationDetails(String uname,String upwd,String email,String mobile)
	{
		try
		{
			rs=st.executeQuery("select * from registration where uname='"+uname+"'"+"");
			boolean b=rs.next();
			if(b==true)
			{
				status="existed";
			}
			else
			{
				int rowCount=st.executeUpdate("insert into registration values('"+uname+"','"+upwd+"','"+email+"','"+mobile+"')"+"");
				if(rowCount==1)
				{
					status="success";
				}
				else
				{
					status="failure";
				}
			}
		}
		catch (Exception e)
		{
			status="failure";
			e.printStackTrace();
		}
		return status;
	}
}
